import {
  Button,
  StyleSheet,
  Text,
  View,
  TouchableOpacity,
  Alert,
} from 'react-native';
import React, {Component} from 'react';
import {createNativeStackNavigator} from '@react-navigation/native-stack';

function HomeScreen(props: any) {
  return (
    <View style={[styles.container]}>
      <Text style={[styles.text]}>Home Screen</Text>
      <Button
        title="跳转新闻页面"
        onPress={() => props.navigation.navigate('News')}
      />
    </View>
  );
}

function NewsScreen(props: any) {
  return (
    <View style={[styles.container]}>
      <Text style={[styles.text]}>News Screen</Text>
      <Button
        title="跳转Home页面"
        onPress={() => props.navigation.navigate('Home')}
      />
    </View>
  );
}

const Stack = createNativeStackNavigator();

export default class index extends Component {
  render() {
    return (
      <Stack.Navigator initialRouteName="News">
        <Stack.Screen
          name="Home"
          component={HomeScreen}
          options={{
            title: '首页',
            headerStyle: {
              backgroundColor: 'tomato',
            },
            headerRight: () => {
              return (
                <TouchableOpacity onPress={() => Alert.alert('hello')}>
                  <Text>hello</Text>
                </TouchableOpacity>
              );
            },
          }}
        />
        <Stack.Screen name="News" component={NewsScreen} />
      </Stack.Navigator>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
  },
  text: {
    fontSize: 40,
  },
});
